package com.qiqidream.admin.common.response;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.io.Serializable;

/**
 * 统一的公共响应体
 * @author QiQiDream
 * @since 2019/12/7 16:28
 */
@Data
@AllArgsConstructor
public class ResponseResult implements Serializable {
    /**
     * 返回状态码
     */
    private Integer code;
    /**
     * 返回信息
     */
    private String msg;
    /**
     * 数据
     */
    private Object data;

    public static ResponseResult success(String msg) {
        return new ResponseResult(ResponseCode.SUCCESS.getCode(), msg,null);
    }

    public static ResponseResult success(ResponseCode responseCode) {
        return new ResponseResult(responseCode.getCode(),responseCode.getMsg(),null);
    }

    public static ResponseResult success(ResponseCode responseCode,Object data) {
        return new ResponseResult(responseCode.getCode(),responseCode.getMsg(),data);
    }

    public static ResponseResult failed(ResponseCode responseCode, String msg) {
        return new ResponseResult(responseCode.getCode(), msg,null);
    }

    public static ResponseResult failed(ResponseCode responseCode) {
        return new ResponseResult(responseCode.getCode(),responseCode.getMsg(),null);
    }

    public static ResponseResult failed(String msg) {
        return new ResponseResult(ResponseCode.FAILURE.getCode(), msg,null);
    }

}
